Title: SQL W3S (By-BKK) / 107 Constraints
Tags: Obsidian_to_Anki

Q: What is the purpose of SQL constraints?
A: To specify rules for the data in a table, ensuring accuracy and reliability

Q: Where can SQL constraints be defined?
A: When creating a table using CREATE TABLE or after using ALTER TABLE

Q: True or False: SQL constraints help limit the type of data that can go into a table.
A: True

Q: What happens if a data action violates a constraint?
A: The action is aborted

Q: What are the types of SQL constraints based on scope?
A: Column level (applies to a column) and table level (applies to the whole table)

Q: Which constraint prevents a column from being NULL?
A: NOT NULL

Q: Which SQL constraint makes sure all values in a column are different?
A: UNIQUE

Q: Which constraint uniquely identifies each row in a table?
A: PRIMARY KEY

Q: What does a FOREIGN KEY constraint do?
A: Prevents actions that would destroy links between tables

Q: Which constraint enforces that values in a column satisfy a specific condition?
A: CHECK

Q: What is the use of the DEFAULT constraint in SQL?
A: Sets a default value for a column if no value is provided

Q: What does CREATE INDEX help with in SQL?
A: Creates and retrieves data from the database quickly

Q: True or False: PRIMARY KEY is a combination of NOT NULL and UNIQUE.
A: True

Q: Give an example of a column level constraint.
A: NOT NULL specified for a single column

Q: Give an example of a table level constraint.
A: PRIMARY KEY set for multiple columns

Q: How do you enforce rules for the data in a table?
A: By using SQL constraints

Q: Reverse card example:
Prevents NULL values in a column
A: What does the NOT NULL constraint do?

Q: Reverse card example:
Ensures all values in a column are different
A: What does the UNIQUE constraint do?

Q: Reverse card example:
Guarantees each row is unique
A: What does the PRIMARY KEY constraint do?

Q: Reverse card example:
Prevents destruction of links between tables
A: What does a FOREIGN KEY constraint do?

Q: Reverse card example:
Enforces a condition on column values
A: What does the CHECK constraint do?

Q: Reverse card example:
Sets a default value for a column
A: What does the DEFAULT constraint do?

Q: Reverse card example:
Speeds up data retrieval
A: What does CREATE INDEX do in SQL?